<template>
  <div class="slice-management">
    <el-table :data="slices" style="width: 100%">
      <el-table-column prop="document_count" label="文档数" />
      <el-table-column prop="character_count" label="字符数" />
      <el-table-column prop="content" label="切片内容" />
      <el-table-column prop="status" label="切片状态">
        <template #default="{ row }">
          <el-tag :type="row.status === 1 ? 'success' : 'warning'">
            {{ row.status === 1 ? '已处理' : '未处理' }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="ctime" label="创建时间" />
      <el-table-column label="操作" width="200">
        <template #default="scope">
          <el-button size="small" @click="handleEdit(scope.row)">编辑</el-button>
          <el-button size="small" type="danger" @click="handleDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { request } from '../../composables/useCommon'

const slices = ref([])

// 获取切片数据
const getSlices = async () => {
  try {
    const res = await request('ragSlice/', 'get', { knowledgeId: 1 }) // 假设 knowledgeId 为 1
    slices.value = res.data.records
  } catch (err) {
    ElMessage.error('获取切片列表失败')
  }
}

// 编辑切片
const handleEdit = (row) => {
  // 编辑逻辑
}

// 删除切片
const handleDelete = (row) => {
  ElMessageBox.confirm(
    '确认要删除该切片吗？',
    '提示',
    {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning',
    }
  ).then(async () => {
    try {
      await request(`ragSlice/${row.id}`, 'delete')
      ElMessage.success('删除成功')
      getSlices()
    } catch (err) {
      ElMessage.error('删除失败')
    }
  })
}

getSlices()
</script>

<style scoped>
.slice-management {
  padding: 20px;
}
</style> 